package com.jerry.constellation.Adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.jerry.constellation.R;
import com.jerry.constellation.bean.StardetialsBean;

import java.util.List;

public class DetailsBaseAdapter extends BaseAdapter {
    private Context mcontext;
    private List<StardetialsBean> mdata;

    public DetailsBaseAdapter(Context context, List<StardetialsBean> data) {
        this.mcontext = context;
        this.mdata = data;
    }

    @Override
    public int getCount() {
        return mdata.size();
    }

    @Override
    public Object getItem(int i) {
        return mdata.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder=null;
        if (view==null) {
            view= LayoutInflater.from(mcontext).inflate(R.layout.stardetails_lv_item,null);
            viewHolder=new ViewHolder(view);
            view.setTag(viewHolder);
        }else{
            viewHolder= (ViewHolder) view.getTag();
        }
        StardetialsBean bean = mdata.get(i);
        viewHolder.title_Tv.setText(bean.getTitle());
        viewHolder.content_Tv.setText(bean.getContent());
        viewHolder.content_Tv.setBackgroundResource(bean.getColor());

        return view;

    }

    class ViewHolder{
        TextView title_Tv;
        TextView content_Tv;

        public ViewHolder(View view) {
           title_Tv =view.findViewById(R.id.stardetails_lv_item_tv_title);
           content_Tv=view.findViewById(R.id.stardetails_lv_item_tv_content);
        }
    }
}
